package ace.j2se.l1;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

public class FileTest {
	public static void main(String[] args) throws IOException {
		String fileName = "aaa.test";
		String postfix = fileName.substring(fileName.indexOf(".") + 1,
				fileName.length());
		String title = fileName.substring(0, fileName.indexOf("."));
		System.out.println(title);
		System.out.println(postfix);

		URL url = new URL("http://www.google.com.hk");
		URLConnection connection = url.openConnection();
		connection.setConnectTimeout(5000);
		connection.setDoInput(true);
		connection.connect();
		InputStream in = connection.getInputStream();
		int c;
		StringBuffer sb = new StringBuffer();
		String imgstr = "<div class=\"box_content_main\" >";
		while ((c = in.read()) != -1) {
			int all = in.available();
			byte[] b = new byte[all];
			in.read(b);
			String webpage = new String(b, "gb2312");
			sb.append(webpage);
		}

		System.out.println(sb);
		System.out.println(sb.indexOf(imgstr));
		// String webpage=new String(buffer,"UTF-8");

		// InputStreamReader reader = new
		// InputStreamReader(connection.getInputStream());
		// char[] buffer = new char[1024];
		//
		// while (reader.read(buffer) != -1) {
		// for (char c : buffer) {
		// System.out.print(c);
		// }
		// }

		BufferedReader reader = new BufferedReader(new FileReader(
				"d:\\file\\new.txt"));
		String line = null;
		List aList = new ArrayList();
		while ((line = reader.readLine()) != null) {
			// System.out.println(line);
			aList.add(line);
		}
		reader.close();
		List bList = new ArrayList();
		reader = new BufferedReader(new FileReader("d:\\file\\10h00m.txt"));
		while ((line = reader.readLine()) != null) {
			// System.out.println(line);
			bList.add(line);
		}
		reader.close();

		int size = aList.size() > bList.size() ? aList.size() : bList.size();
		for (int i = 0; i < size; i++) {
			String aVal = (String) aList.get(i);
			String bVal = (String) bList.get(i);
			if (!aVal.equals(bVal)) {
				System.out.println(aVal + "    " + bVal);
			}
		}
	}
}
